/*
 * Created by JFormDesigner on Tue Apr 24 14:47:54 CEST 2012
 */

package GUIComponents;

import java.awt.*;
import java.util.*;
import javax.swing.*;
import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;
import text.DejPocty;

/**
 * @author Karel Novak
 */
public class StatusBar2 extends JPanel implements Runnable{
  String text;
  Thread t;

  public StatusBar2(String s) {
    initComponents();

    if (s != null && s.length() > 0) {
      this.text = s;
      this.t = new Thread(this);
      this.t.setName("StatusBar2");
      this.t.setPriority(Math.round(Thread.MAX_PRIORITY / 3));
    }
  }

  void vynulujStatusBar() {
    lbl_nmbr_chars.setText("0");
    lbl_nmbr_sentences.setText("0");
    lbl_nmbr_words.setText("0");
  }

  public void run() {
    if (text == null || text.length() == 0) {
      vynulujStatusBar();
    } else {
      int[] slova = DejPocty.pocetSlov(text);
      lbl_nmbr_chars.setText(Integer.toString(DejPocty.pocetZnaku(text)));
      lbl_nmbr_words.setText(Integer.toString(slova[0]));
      lbl_nmbr_sentences.setText(Integer.toString(DejPocty.pocetVet2(text)));
    }
  }

  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Karel Novak
    ResourceBundle bundle = ResourceBundle.getBundle("cs");
    pnl_sentences = new JPanel();
    lbl_sentences_count = new JLabel();
    lbl_nmbr_sentences = new JLabel();
    pnl_words = new JPanel();
    lbl_word_count = new JLabel();
    lbl_nmbr_words = new JLabel();
    pnl_chars = new JPanel();
    lbl_char_count = new JLabel();
    lbl_nmbr_chars = new JLabel();

    //======== this ========

    // JFormDesigner evaluation mark
    setBorder(new javax.swing.border.CompoundBorder(
      )); addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

    setLayout(new FormLayout(
      "2*(default, $lcgap), default",
      "default"));

    //======== pnl_sentences ========
    {
      pnl_sentences.setBorder(UIManager.getBorder("TitledBorder.border"));
      pnl_sentences.setLayout(new FormLayout(
        "default, $lcgap, 38dlu",
        "default"));

      //---- lbl_sentences_count ----
      lbl_sentences_count.setText(bundle.getString("StatusBar.lbl_sentences_count.text"));
      pnl_sentences.add(lbl_sentences_count, CC.xy(1, 1));

      //---- lbl_nmbr_sentences ----
      lbl_nmbr_sentences.setName(bundle.getString("StatusBar.lbl_nmbr_sentences.name"));
      lbl_nmbr_sentences.setText(bundle.getString("StatusBar.lbl_nmbr_sentences.text"));
      pnl_sentences.add(lbl_nmbr_sentences, new CellConstraints(3, 1, 1, 1, CC.RIGHT, CC.DEFAULT, new Insets(0, 0, 0, 5)));
    }
    add(pnl_sentences, CC.xy(5, 1));

    //======== pnl_words ========
    {
      pnl_words.setBorder(UIManager.getBorder("TitledBorder.border"));
      pnl_words.setName(bundle.getString("StatusBar.pnl_words.name"));
      pnl_words.setToolTipText(bundle.getString("StatusBar.pnl_words.toolTipText"));
      pnl_words.setLayout(new FormLayout(
        "default, $lcgap, 38dlu",
        "default"));

      //---- lbl_word_count ----
      lbl_word_count.setText(bundle.getString("StatusBar.lbl_word_count.text"));
      pnl_words.add(lbl_word_count, CC.xy(1, 1));

      //---- lbl_nmbr_words ----
      lbl_nmbr_words.setName(bundle.getString("StatusBar.lbl_nmbr_words.name"));
      lbl_nmbr_words.setText(bundle.getString("StatusBar.lbl_nmbr_words.text"));
      pnl_words.add(lbl_nmbr_words, new CellConstraints(3, 1, 1, 1, CC.RIGHT, CC.DEFAULT, new Insets(0, 0, 0, 5)));
    }
    add(pnl_words, CC.xy(3, 1));

    //======== pnl_chars ========
    {
      pnl_chars.setBorder(UIManager.getBorder("TitledBorder.border"));
      pnl_chars.setLayout(new FormLayout(
        "default, $lcgap, 38dlu",
        "default"));

      //---- lbl_char_count ----
      lbl_char_count.setText(bundle.getString("StatusBar.lbl_char_count.text"));
      pnl_chars.add(lbl_char_count, CC.xy(1, 1));

      //---- lbl_nmbr_chars ----
      lbl_nmbr_chars.setName(bundle.getString("StatusBar.lbl_nmbr_chars.name"));
      lbl_nmbr_chars.setText(bundle.getString("StatusBar.lbl_nmbr_chars.text"));
      pnl_chars.add(lbl_nmbr_chars, new CellConstraints(3, 1, 1, 1, CC.RIGHT, CC.DEFAULT, new Insets(0, 0, 0, 5)));
    }
    add(pnl_chars, CC.xy(1, 1));
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
  }

  // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
  // Generated using JFormDesigner Evaluation license - Karel Novak
  private JPanel pnl_sentences;
  private JLabel lbl_sentences_count;
  private JLabel lbl_nmbr_sentences;
  private JPanel pnl_words;
  private JLabel lbl_word_count;
  private JLabel lbl_nmbr_words;
  private JPanel pnl_chars;
  private JLabel lbl_char_count;
  private JLabel lbl_nmbr_chars;
  // JFormDesigner - End of variables declaration  //GEN-END:variables


  public String getText() {
    return text;
  }
}
